﻿//创建时间: 2010-12-14
//创建作者: 李晓忠
//功能说明: 广告列表
//最后修改: 2010-12-14
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;

using System.Data;
using System.Text;
using System.Collections;
using Newtonsoft.Json;

namespace TRPOP.CMS.Web.Admin
{
    public partial class advertisement_list : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_strPagePermissionExtraKey = "Plugin_Advertisement";
        }
        #endregion

        #region 页面变量
        protected string m_title = "广告列表";
        protected int m_intRecordCount = 0;
        protected AdvscontentManage mAdvscontentManage = new AdvscontentManage();
        protected string m_ConfigTypeKey = SYSConfig.AdsVar;
        protected string m_ParamKey = SYSConfig.AdsParamTypeKey;
        public string strEditAndDel = "edit_del";
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        protected void btSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            LinkButton lbtn = (LinkButton)sender;
            int intID = 0;
            int.TryParse(lbtn.CommandArgument, out intID);       
            SubmitAlertDelete(mAdvscontentManage.DeleteInfoById(intID));
            base.SaveLog(Plugin.LogKeys.OperObject.PluginOper, Plugin.LogKeys.OperResult.DelSubmit, m_ConfigTypeKey+":"+intID);
            BindData();
        }
        #endregion

        #region 页面方法


        void BindData()
        {
            string strCondation = string.Empty;
            if (!txtAdNaneLike.Text.IsEmpty())
            {
                strCondation = " and Name like '%" + txtAdNaneLike.Text.Trim().SQLFilter() + "%' ";
            }
            if (Pager.PageSize <= 0) { Pager.PageSize = SYSConfig.SystemVar_AdminContentPageNum; }
            rptList.DataSource = mAdvscontentManage.GetListByPager(Pager.CurrentPage, Pager.PageSize, strCondation, " AdID DESC", out m_intRecordCount);
            Pager.ShowRecordCount = true;
            Pager.ShowPageSize = true;
            Pager.ShowCurrentPage = true;
            Pager.RecordCount = m_intRecordCount;
            rptList.DataBind();
        }
        protected string BindRefCode(object id,object pagename,object model)
        {
            string str = "";
            string url = SYSConfig.SystemVar_SiteURL.Trim();
            if (url.EndsWith("/"))
            {
                url = url.Substring(0, SYSConfig.SystemVar_SiteURL.Length - 1);
            }
            if (model.ToString() == "0")
            {
                string strRoot = SYSConfig.AdvertisementRoot;
                string path = "";
                if (strRoot.EndsWith("/"))
                {
                    path = strRoot + pagename + ".js";
                }
                else
                {
                    path = strRoot + "/" + pagename + ".js";
                }
              
                url = url + path;
                str = url;
            }
            else
            {
                str = SYSConfig.AdvertisementDynamicAccessUrl;
                if (str.IndexOf("?") > 0)
                {
                    str += "&id=" + id.ToString();
                }
                else
                {
                    str += "?id=" + id.ToString();
                }
                str = url + str;
            }
            str = string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>",str);
            return str.Trim();
        }
        #endregion
    }
}
